package gq.example.service.impl;

import gq.example.entity.Users;
import gq.example.entity.UsersAndRole;
import gq.example.mapper.UsersAndRoleMapper;
import gq.example.mapper.UsersMapper;
import gq.example.service.IUsersService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class UsersServiceImpl implements IUsersService {

    @Autowired
    private UsersMapper usersMapper;

    @Autowired
    private UsersAndRoleMapper usersAndRoleMapper;

    @Override
    public int addUser(Users user) {
        int i = usersMapper.addUser(user);
        usersAndRoleMapper.addRole(new UsersAndRole(user.getUid(), 1));
        return i;
    }

    @Override
    public Users userExist(String username,String email) {
        return usersMapper.userExist(username,email);
    }

    @Override
    public Users findUserByUsername(String username) {
        return usersMapper.findUserByUsername(username);
    }

    @Override
    public List<Users> findUsersByUsername(Users users) {
        return usersMapper.findUsersByUsername(users);
    }

    @Override
    public Users findUserByUserId(Integer id) {
        return usersMapper.findUserByUserId(id);
    }

    @Override
    public int deleteUser(Integer id) {
        int i = usersAndRoleMapper.deleteRoleById(id);
        return usersMapper.deleteUser(id);
    }

    @Override
    public int updateUser(Users user) {
        return usersMapper.updateUser(user);
    }

    @Override
    public List<String> getEmails(Integer id) {
        return usersMapper.getEmails(id);
    }

    @Override
    public String getNameById(Integer id) {
        return usersMapper.getNameById(id);
    }

    @Override
    public int forgetPassword(Users user) {
        return usersMapper.forgetPassword(user);
    }

    @Override
    public Users findUserByEmail(String email) {
        return usersMapper.findUserByEmail(email);
    }
}
